package com.dc.project_kotlin

import com.dc.base.BaseApp
import com.dc.project_kotlin.event.AppViewModel
import com.dc.project_kotlin.event.EventViewModel
import com.dc.project_kotlin.loadcallback.EmptyCallback
import com.dc.project_kotlin.loadcallback.ErrorCallback
import com.dc.project_kotlin.loadcallback.LoadingCallback
import com.kingja.loadsir.callback.SuccessCallback
import com.kingja.loadsir.core.LoadSir
import com.tencent.mmkv.MMKV

//Application全局的ViewModel，里面存放了一些账户信息，基本配置信息等
val appViewModel: AppViewModel by lazy { App.appViewModelInstance }

//Application全局的ViewModel，用于发送全局通知操作
val eventViewModel: EventViewModel by lazy { App.eventViewModelInstance }

class App : BaseApp() {

    companion object {
        lateinit var instance: App
        lateinit var appViewModelInstance: AppViewModel
        lateinit var eventViewModelInstance: EventViewModel
    }

    override fun onCreate() {
        super.onCreate()
        MMKV.initialize(this.filesDir.absolutePath + "/mmkv")
        instance = this
        appViewModelInstance = getAppViewModelProvider().get(AppViewModel::class.java)
        eventViewModelInstance = getAppViewModelProvider().get(EventViewModel::class.java)

        LoadSir.beginBuilder()
            .addCallback(LoadingCallback())//加载
            .addCallback(ErrorCallback())//错误
            .addCallback(EmptyCallback())//空
            .setDefaultCallback(SuccessCallback::class.java)
            .commit()
    }
}